package com.atstudy.obj;

import java.io.*;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/29 14:27
 * @copyright: 博为峰
 */
public class ObjectInputOutputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        m1(); //-8983764327764918318
        m2();
    }

    private static void m2() throws IOException, ClassNotFoundException {
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\admin\\Desktop\\java29\\io\\stu.obj");
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        Student student = (Student) objectInputStream.readObject();
        System.out.println(student);
    }

    private static void m1() throws IOException {
        Student student = new Student("张三", 20);
        student.sex = "男";
        student.balance = 10000;
        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\admin\\Desktop\\java29\\io\\stu.obj");
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(student);
    }
}
